package com.uwo.house.service.serviceImpl;

import com.uwo.house.beans.request.MaterialDetailReq;
import com.uwo.house.beans.request.MaterialListReq;
import com.uwo.house.beans.request.MaterialStatusReq;
import com.uwo.house.beans.response.ShipmentRemarkResp;
import com.uwo.house.dao.MaterialListDao;
import com.uwo.house.dao.MaterialStatusDao;
import com.uwo.house.dao.ShipmentRemarkDao;
import com.uwo.house.dao.SupplierMessageDao;
import com.uwo.house.service.IMaterialListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by YZYG on 2017/7/17.
 */
@Service
public class MaterialListService implements IMaterialListService{
    @Autowired
    public MaterialListDao materialListDao;

    @Autowired
    public MaterialStatusDao materialStatusDao;

    @Autowired
    public SupplierMessageDao supplierMessageDao;

    @Autowired
    ShipmentRemarkDao shipmentRemarkDao;

    public List<MaterialStatusReq> getMaterialList(String supplierId, String orderId, int materialSts) {
        return materialStatusDao.getMaterialList(supplierId,orderId, materialSts);
    }

    public List<MaterialDetailReq> getMaterialDetailByPlanId(int planId) {
        return materialStatusDao.getMaterialDetailByPlanId(planId);
    }
    public int updateMaterialStatus(String id){
        return materialStatusDao.updateMaterialStatus(id);
    }

    //@Transactional
    public int deleteMaterialById(int id){
        int result1=  materialStatusDao.deleteMaterialStatus(id);
        //int result2 =  deleteMaterialById(id);
        if (result1 == 1) {
            return 1;
        } else {
            return 0;
        }
    }



    public ShipmentRemarkResp getShipmentDetailByMaterialStatusId(String id) {
        return shipmentRemarkDao.getShipmentRemarkResp(id);
    }

    @Transactional
    public int saveShipment(ShipmentRemarkResp shipmentRemarkResp) {
        if (null != shipmentRemarkResp) {
            int result1 = shipmentRemarkDao.saveShipment(shipmentRemarkResp);
            int result2 =  updateMaterialStatus(shipmentRemarkResp.getMaterialStatusId());
            if (result1 == 1 && result2 == 1) {
                return 1;
            }
        }
        return 0;
    }

    public int deleteMessageByMessageId(int messageId) {
        return supplierMessageDao.deleteMessageByMessageId(messageId);
    }

    /**
     * 供应商端保存清单
     * @param materialStatusReq
     * @return
     */
    public int addMaterialStatus(MaterialStatusReq materialStatusReq){
        return materialStatusDao.addMaterialStatus(materialStatusReq);
    }

    /**
     * 供应商、项目经理、监理端显示材料数据详情
     * @param orderId
     * @return
     */
    public List<MaterialListReq> getMaterialDetailByOrderId(String orderId) {
        return materialListDao.getMaterialDetailByOrderId(orderId);
    }

    /**
     * 供应商显示材料数据详情
     * @param planId
     * @return
     */
    public List<MaterialListReq> getMaterialDetailsByPlanId(Integer planId) {
        return materialListDao.getMaterialDetailByPlanId(planId);
    }
}
